// pages/recommendOrg/recommendOrg.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    search: {
      pageNumber: 1,
      pageSize: 10,
      totalPages: 0
    },
    isindex:false,
  },
  addorgbtn() {
    wx.redirectTo({
      url: '/pages/recommendOrg/recommendOrg'
    })
  },
  addorgbtn1() {
    wx.redirectTo({
      url: '/pages/creat/creat'
    })
  },
  list: function (append) {
    var that = this;
    var url=''
    var data={}
    if(that.data.isindex){
      url ='orgmini/home/getOrg'
      data={
        type:5
      }
    }else{
      url = 'orgmini/org/recommendList'
        data = that.data.search
    }
    app.req({
      url: url,
      data: data,
      success: function (res) {
        if (200 == res.code) {
          if(that.data.isindex){
            that.toggle("list", res.data);
          }else{
          var list = that.data.list;
          var nowList = res.data.rows;
          that.toggle("list", append ? list.concat(nowList) : nowList);
          that.toggle("search.totalPages", res.data.totalPages * 1);
          }
        }
      }
    });
  },
  toPage(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/orgHome/orgHome?id='+id,
    })
  },
  tohomes(e) {
    var id = e.currentTarget.dataset.id;
    var orgSearch = e.currentTarget.dataset.orgsearch * 1
    wx.redirectTo({
      url: '/pages/orgRelease/orgRelease?id=' + id + "&orgSearch=" + orgSearch,
    })
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.isindex==1){
      this.toggle("isindex", true);
      wx.setNavigationBarTitle({
        title: '选择组织'
      })
    }else{
      wx.setNavigationBarTitle({
        title: '推荐组织'
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.list()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    var search = that.data.search;
    if (!that.data.isindex && search.totalPages > search.pageNumber) {
      that.toggle("search.pageNumber", search.pageNumber + 1);
      that.list(true);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})